package main

import (
	"context"
	"fmt"
	"time"
)

//  portal function handelRequest
func handelRequest(ctx context.Context) {
	go WriteRedis(ctx)
	go WriteDatabases(ctx)
	for {
		select {
		case <-ctx.Done():
			fmt.Println("HandelRequest DONE ")
			return
		default:
			fmt.Println("HandelRequest is running ")
			time.Sleep(2 * time.Second)

		}
	}

}

// function 1  for handelRequest
func WriteRedis(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("WriteRedis DONE ")
			return
		default:
			fmt.Println("WriteRedis is running ")
			time.Sleep(2 * time.Second)

		}
	}
}

// function 2 for handelRequest
func WriteDatabases(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("WriteDatabases DONE ")
			return
		default:
			fmt.Println("WriteDatabases is running ")
			time.Sleep(2 * time.Second)

		}
	}
}
func main() {
	// ctx, canel := context.WithCancel(context.Background())
	// timeout context
	ctx, _ := context.WithTimeout(context.Background(), time.Second*3)
	go handelRequest(ctx)
	time.Sleep(5 * time.Second)
}
